package com.entitymapper;

import com.entitymapper.field.FieldMapperToRead;
import com.entitymapper.field.FieldMapperToWrite;
import com.entitymapper.field.ResultSet;
import com.entitymapper.xml.rfid.Configure;

/**
 * 
 * @author hhf
 */
public class EntityMapperImpl implements EntityMapper{

	private ResultSetManager resultSetManager;
	
	public EntityMapperImpl(ResultSetManager resultSetManager) {
		this.resultSetManager = resultSetManager;
		
	}
	@Override
	public Object readAsObject(Class<?> entityType, FieldMapperToRead fmtr)
			throws EntityMapperException {
		ResultSet rs = resultSetManager.createResultSet(entityType);
		return fmtr.mappering(rs);
	}

	@Override
	public void writeFromObject(Object object, FieldMapperToWrite fmtw) throws EntityMapperException {
		ResultSet rs = resultSetManager.createResultSet(object.getClass());
		fmtw.mappering(rs,object);
	}
	
	public void configure(String fileName) {
		Configure configure = new Configure(fileName);
		configure.configure();
	}
	public void configure() {
		Configure configure = new Configure();
		configure.configure();
	}
	
	public ResultSetManager getResultSetManager() {
		return resultSetManager;
	}
	public void setResultSetManager(ResultSetManager resultSetManager) {
		this.resultSetManager = resultSetManager;
	}
}
